package com.ego.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    //密码解析器
    @Bean
    protected PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.formLogin()
                .loginPage("/")
                .successForwardUrl("/loginSuccess")
                .loginProcessingUrl("/login");   //控制器

        http.authorizeRequests()
                //静态资源也要放行
                .antMatchers("/","/css/**","/js/**").permitAll()
                .anyRequest().authenticated();
        http.csrf().disable();
        //图片上传的时候 关闭在响应头中添加deny
        http.headers().frameOptions().disable();

    }
}
